﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using webapp4U;
using webapp4U.BOL;


public partial class UserControl_ControlInNghiepVuDoiGia : System.Web.UI.UserControl
{
    ClassExecute.ClassExecute dt;
    string str = webapp4U.Configuration.CurrentConnectionString;
    string error = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DataBind();
        }
        if (ViewState["strSoHoaDon"] != null)
        {
            ControlReportViewer1.ReportViewer.Report = CreateReport(ViewState["strSoHoaDon"].ToString());
        }
    }
    public override void DataBind()
    {
        if (Session["Sitecode"] != null)
        {
            dt = new ClassExecute.ClassExecute();
            DataTable db = dt.Get_Data_DataTable(str, ref error, "ls_getChangePriceTranList", CommandType.StoredProcedure, new SqlParameter("@siteCode", Session["Sitecode"].ToString()));
            if (db.Rows.Count > 0)
            {
                grdvNghiepVuDoiGiaLists.DataSource = db;
                grdvNghiepVuDoiGiaLists.DataBind();
            }
        }
    }

    protected void grdvNghiepVuDoiGiaLists_SelectedIndexChanged(object sender, EventArgs e)
    {
        string strSoHoaDon = grdvNghiepVuDoiGiaLists.SelectedDataKey.Value.ToString();
        ViewState["strSoHoaDon"] = strSoHoaDon;
        ControlReportViewer1.ReportViewer.Report = CreateReport(strSoHoaDon);
        DataBind();
        UpdatePanel1.Update();
        TabContainer1.ActiveTabIndex = 1;        
    }

    protected void grdvNghiepVuDoiGiaLists_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grdvNghiepVuDoiGiaLists.PageIndex = e.NewPageIndex;
        DataBind();
    }
   
    protected void imgBtnAdd_Click(object sender, ImageClickEventArgs e)
    {
        DataBind();
    }

    DevExpress.XtraReports.UI.XtraReport CreateReport(string strSoHoaDon)
    {
        XtraReportInNghiepVuDoiGia tableReport = new XtraReportInNghiepVuDoiGia();
        if (Session["Sitecode"] != null)
        {         
           
            dt = new ClassExecute.ClassExecute();
            DataSet ds = new DataSet();

            ds = dt.Get_Data_DataSet(str, ref error, "ls_getChangePriceTranDetail4Print", CommandType.StoredProcedure,
                new SqlParameter("@siteCode", Session["Sitecode"].ToString()),
                new SqlParameter("@trnNo", strSoHoaDon));

            tableReport.SetReportParameter(ds);
        }
        return tableReport;
    }
}
